package net.whatmark.playavillain.meshikau.page;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mobylet.core.Mobylet;
import org.mobylet.core.MobyletFactory;
import org.mobylet.core.device.Device;
import org.mobylet.core.device.DeviceDisplay;
import org.mobylet.core.device.DeviceProfile;
import org.t2framework.commons.util.Logger;
import org.t2framework.t2.annotation.core.ActionPath;
import org.t2framework.t2.annotation.core.Default;
import org.t2framework.t2.annotation.core.Page;
import org.t2framework.t2.contexts.Request;
import org.t2framework.t2.contexts.WebContext;
import org.t2framework.t2.navigation.Forward;
import org.t2framework.t2.spi.Navigation;

@Page("profile")
public class ProfilePage {

	static Logger logger = Logger.getLogger(ProfilePage.class);

	public Navigation beforeIndex(WebContext context) {
		logger.debug("before index.");
		return null;
	}

	@Default
	public Navigation index(Request request) {

		return Forward.to("/pages/profile.jsp");
	}

	@ActionPath
	public Navigation request(HttpServletRequest request) {
		System.out.println("request.getContextPath() : "
				+ request.getContextPath());

		Mobylet mobylet = MobyletFactory.getInstance();
		Device device = mobylet.getDevice();
		DeviceDisplay display = device.getDeviceDisplay();
		DeviceProfile profile = device.getDeviceProfile();
		request.setAttribute("carrier", mobylet.getCarrier());
		request.setAttribute("device", profile.get("機種名"));
		request.setAttribute("display_width", display.getWidth());
		request.setAttribute("display_height", display.getHeight());
		request.setAttribute("profile", device.hasGps() ? "対応" : "非対応");
		return Forward.to("/pages/profile.jsp");
	}

	@ActionPath("struts")
	public Navigation likeStrutsType(HttpServletRequest request,
			HttpServletResponse response) {
		System.out.println("request.getContextPath() : "
				+ request.getContextPath());

		return Forward.to("/pages/profile.jsp");
	}
}
